<?php
/**
 * Subactegoryadmin_Data_Insertsubcategory
 * insert subcategory data
 * @author Adrian Stolarski
 */
class Subcategoryadmin_Data_Insertsubcategory implements Subcategoryadmin_Data_Mainable, 
        Subcategoryadmin_Data_Preparable, Subcategoryadmin_Data_Redirectable{
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query 
     * database query handler
     */
    public $database_query;
    /**
     *
     * @var type $redirect_action
     * redirect action handler
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * insert new sub category into database
     * 
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        //echo $this->database_query;
        //die();
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action($variables);
    }
    
    /**
     * preapre_query()
     * insert sub category data into database
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "INSERT INTO "
                . "page_sub_category("
                . "sub_category_name"
                . ", "
                . "sub_category_title"
                . ", "
                . "sub_category_keywords"
                . ", "
                . "sub_category_description"
                . ", "
                . "sub_category_access_level"
                . ", "
                . "sub_category_module_id"
                . ", "
                . "sub_category_main_category_id"
                . ") "
                . "VALUES"
                . "("
                . "'"
                .$variables['sub_category_name'].
                "', '"
                .$variables['sub_category_title'].
                "', '"
                .$variables['sub_category_keywords'].
                "', '"
                .$variables['sub_category_description'].
                "', '"
                .$variables['sub_category_access_level'].
                "', '"
                .$variables['sub_category_module_id'].
                "', '"
                .$variables['sub_category_main_category_id'].
                "');";
    }
    
    /**
     * redirect_action()
     * redirect action
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
       $this->redirect_action = new Subcategoryadmin_Data_Subcategoryredirect;
       $this->redirect_action->main($variables);
    }

}
